package spring.board;

import java.security.Principal;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import spring.board.service.MainService;

@Controller
public class BoardController {
	
	@Autowired
	private MainService mainService;
	
	@RequestMapping("/hello.do")
	public void hello(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		model.put("title", "나의 첫 번째 스프링");
	}
	
	@RequestMapping("/today.do")
	public void today(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		model.put("today", mainService.getToday());
	}
	/*
	@RequestMapping("/login.do")
	public void login(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		
	}
	*/
	@RequestMapping("/loginFail.do")
	public void loginFail(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		
	}
	
	@RequestMapping("/main.do") 
	public void main(@RequestParam Map<String, Object> paramMap, ModelMap model, Principal principal) throws Throwable {
		// 로그인 후 로그인 한 아이디를 고른다.
		String name = principal.getName();
		
		System.out.println("******************************************");
		System.out.println(name);
		
		model.addAttribute("username", name);
	}
	
	@RequestMapping("/logout.do")
	public void logout(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		
	}
}
